<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="22">
            <el-form-item label="名称" prop="label"
                :rules="[
                  {required: true, message:'名称不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.label" placeholder="请填写名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="22">
            <el-form-item label="键值" prop="value"
                :rules="[
                  {required: true, message:'键值不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.value" placeholder="请填写键值"></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="22">
            <el-form-item label="文件类型" prop="fileType"
                :rules="[
                 ]">
                <el-select v-model="inputForm.fileType" placeholder="请选择文件"  style="width: 100%;">
                    <el-option
                      v-for="item in $dictUtils.getDictList('file_type')"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="22">
            <el-form-item label="资源格式" prop="format"
                :rules="[
                 ]">
              <el-input v-model="inputForm.format" placeholder="资源格式 例如: .png,.jpg"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="22" v-show="inputForm.fileType === '2'">
            <el-form-item label="宽度" prop="width"
                :rules="[
                  {validator: validator.isIntGtZero, trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.width" placeholder="请填写宽度"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="22" v-show="inputForm.fileType === '2'">
            <el-form-item label="高度" prop="height"
                :rules="[
                  {validator: validator.isIntGtZero, trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.height" placeholder="请填写高度"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="22">
            <el-form-item label="数量限制" prop="limit"
                :rules="[
                  {validator: validator.isIntGtZero, trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.limit" placeholder="请填写数量"     ></el-input>
           </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        groupType: '',
				index: 0,
        inputForm: {
          label: '',
          value: '',
          format: '.png,.jpg',
          width: '256',
          height: '256',
          fileType: '2',
          limit: 1
        }
      }
    },
    components: {
    },
    methods: {
      init (method, inputForm, index, groupType) {
        this.method = method
        this.groupType = groupType
				this.index = index
        if (method === 'add') {
          this.title = `新建配置`
        } else if (method === 'edit') {
          this.inputForm = inputForm
          this.title = '修改配置'
        } else if (method === 'view') {
          this.inputForm = inputForm
          this.title = '查看配置'
        }
        this.visible = true
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.inputForm.limit = parseInt(this.inputForm.limit);
            this.$emit('onComplete', this.method, JSON.parse(JSON.stringify(this.inputForm)), this.index, this.groupType);
            this.visible = false
          }
        })
      }
    }
  }
</script>
